import api from '@/commonJS/api.js';
import common from '@/commonJS/common.js';
const dayjs = require("dayjs");
export const hunhe = {
	methods: {
		// 获取订单详情
		mixinOrderDetail(orderId, type) {
			/**
			 * orderId：订单 id
			 * type：1（订单详情）、2（评价晒单）
			 */
			const _this = this;
			common.ajaxFn(api.order_detail + orderId, 'GET').then((res) => {
				console.log('订单详情', res);
				if (res) {
					_this.pageData = res.data.data;
					if (type == 1) {
						_this.zjtimelineobj = {
							real_name: res.data.data.real_name,
							user_phone: res.data.data.user_phone,
							user_address: res.data.data.user_address,
						}
						// 付款倒计时
						const time = dayjs().unix() - _this.pageData.add_time;
						time > 1800 ? _this.pageData.hycountdown = 0 : _this.pageData.hycountdown = 1800 -
							time;
						// 日期前发货
						_this.pageData.hyfahuotime = dayjs(_this.pageData._add_time).add(1, 'day').format(
							'YYYY-MM-DD HH:mm:ss');
					} else if (type == 2) {
						_this.arrData = [];
						let obj;
						for (let i = 0; i < _this.pageData.cartInfo.length; i++) {
							obj = {
								pingjia: 0,
								pjContent: '',
								imgArr: [],
								unique: _this.pageData.cartInfo[i].unique
							}
							_this.arrData.push(obj);
						}
						console.log('混合打印', _this.arrData);
					}
				}
			});
		},
		// 复制
		mixinCopy(res) {
			uni.setClipboardData({
				data: res,
				success() {
					uni.showToast({
						title: '复制成功',
						icon: 'none',
						mask: true
					});
				}
			});
		},
		// 催发货
		mixinFahuo() {
			uni.showToast({
				title: '已通知商家尽快发货',
				icon: 'none',
				mask: true
			});
		},
		// 确认收货
		mixinShouhuo(orderId) {
			const _this = this;
			uni.showModal({
				title: '提示',
				content: '请确认已经收到包裹？',
				success(res) {
					if (res.confirm) {
						const obj = {
							uni: orderId
						}
						common.ajaxFn(api.order_shouhuo, 'POST', obj).then((res) => {
							console.log('确认收货', res);
							if (res) {
								uni.showToast({
									title: '收货成功',
									icon: 'none',
									mask: true
								});
								setTimeout(() => {
									uni.redirectTo({
										url: `/pagesShopping/jiaoyichenggong?orderId=${orderId}`
									});
								}, 1000);
							}
						});
					}
				}
			});
		},
		// 立即支付
		mixinNowPay(cart_id) {
			console.log('cart_id', cart_id);
			if (cart_id.length == 1) {
				uni.navigateTo({
					url: `/pagesShopping/confirmOrder?cartId=${cart_id[0]}&from=detail`
				});
			} else {
				uni.navigateTo({
					url: `/pagesShopping/confirmOrder?cartId=${cart_id.join()}&from=cart`
				});
			}
		},


	}
}